<?php
/**
 *  获取服务器访问外网的ip地址
 */

function get_srv_ip() {
	$service_from = 'ip138';
	$url = 'http://www.ip138.com/ip2city.asp';
	$str = file_get_contents($url);
	if (preg_match("/\[([\w\.]+)\]/", $str, $matches)) {
		return $matches[1];
	}
	return NULL;
}
/**
 *  获取ip信息
 */

function get_ip_info($ip,$attr=array()) {
	$service_from = 'sina';
	$cityInfo = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip={$ip}&charset=utf-8&format=json");
	$info = @json_decode($cityInfo, TRUE);
	if (is_array($info) && $info['ret'] == 1) {
		return array(
			'country' => $info['country'],
			'provice' => $info['provice'],
			'city' => $info['city'],
			'isp' => $info['isp'], //有运营商
			'net_start' => $info['start'],
			'net_end' => $info['end']
		);
	}
	else {
		return NULL;
	}
}
?>